package com.hainatong.jcmvvmbase.mainhome.fragment.holiday;

import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.hainatong.jcmvvmbase.MvvmLazyFragment;
import com.hainatong.jcmvvmbase.MyFragmentPagerAdapter;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.FragmentMyHolidayBinding;
import com.hainatong.jcmvvmbase.mainhome.entity.TabEntity;
import com.hainatong.jcmvvmbase.mainhome.fragment.HolidayMgrFragment;
import com.hainatong.mvvmbase.base.NoViewModel;

import java.util.ArrayList;
import java.util.List;

public class MyHolidayFragment extends MvvmLazyFragment<FragmentMyHolidayBinding, NoViewModel>
{

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private List<Fragment> fragmentList;
    private MyFragmentPagerAdapter vpAdapter;


    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_my_holiday;
    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void initParameters()
    {
        mTabEntities.add(new TabEntity(getString( R.string.my_holiday ), R.mipmap.ic_holiday_active, R.mipmap.ic_holiday_unactive));
        mTabEntities.add(new TabEntity(getString( R.string.holiday_history ), R.mipmap.ic_leavehistory_active, R.mipmap.ic_leavehistory_unactive));
    }

    @Override
    protected void onRetryBtnClick()
    {
    }

    @Override
    protected void initView(View view)
    {
        fragmentList = new ArrayList<>();
        fragmentList.add( new HolidayMgrFragment());
        fragmentList.add( new HolidayHistoryFragment());

        vpAdapter = new MyFragmentPagerAdapter(getActivity(),fragmentList);
        viewDataBinding.vp2.setAdapter( vpAdapter );
        viewDataBinding.vp2.setOffscreenPageLimit(2);

        viewDataBinding.comTl.setTabData(mTabEntities);
        viewDataBinding.comTl.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position)
            {
                viewDataBinding.vp2.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        viewDataBinding.vp2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position)
            {
                viewDataBinding.comTl.setCurrentTab( position );
            }
        });

    }

    @Override
    protected void lazyLoad()
    {

    }
}
